
efform_onload = function ()
{
	var fdPlanStatus = decodeURI($('#fdPlanStatus').val());
	if(fdPlanStatus != '草拟')
		hideAndShowSubButtons(false);
	else
		hideAndShowSubButtons(true);
}

//查询
button_query_onclick = function(){
	efgrid.submitInqu("ef_grid_result","ZM","ZMCP06","query");
}
//插入
button_insert_onclick = function(){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	efgrid.submitForm("ef_grid_result","ZM","ZMCP06","insert",true);
}
//删除
button_delete_onclick = function(){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)
		return; 
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r)efgrid.submitForm("ef_grid_result","ZM","ZMCP06","delete",true);
	});
}
//修改
button_update_onclick = function(){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdPlanStatus")!="草拟")
		{
			EFAlert("只能对草拟的记录进行修改！"); return;
		}
	}
	efgrid.submitForm("ef_grid_result","ZM","ZMCP06","update",true);
}
//退回
button_revert_onclick = function(){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{	
		var fdShow = grid.getCellValueByColumnName(rows[i],"fdShow");
		if(fdShow!="1")
		{
			EFAlert("只能对上报过来的记录进行退回！"); return;
		}
		EFConfirm('你确认要退回吗?', '确认框', function(r) {
			if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCP06","revert",true);
		});
	}
}
//新增行后的回调函数
efgrid_afterAddNewRow = function(grid_id){
	var grid = efgrid.getGridObject("ef_grid_result");
	var rows = grid.getCheckedRows(); 
	var id = $('#fdProduceplanId').val();//计划id
	var fdCreator=$('#fdCreator').val();//编制人
	var fdCreateDepartment=$('#fdCreateDepartmentId').val();//部门
	var Ryear = $('#fdPlanYear').val();//获得年
	var Rmonth = $('#fdPlanMonth').val();//获得月
    var now = new Date();
    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    if(month > 12) {
    	month = 1;
    	year += 1;
    }
    if(month < 10) month = "0"+month;
    var day = now.getDate();            //日 
    var clock = year + "-" + month + "-";
    if(day < 10) clock += "0";
    clock += day;
	for(var i = 0 ; i < rows.length;i++){
		grid.getBlockData().setCell(rows[i], "fdPlanStatus", "草拟");
		grid.getBlockData().setCell(rows[i], "fdPlanYear", Ryear);
		grid.getBlockData().setCell(rows[i], "fdPlanMonth", Rmonth);
		grid.getBlockData().setCell(rows[i], "fdCreator", fdCreator);
		grid.getBlockData().setCell(rows[i], "fdCreateDepartmentId", fdCreateDepartment);
		grid.getBlockData().setCell(rows[i], "fdCreateDate", clock);
		grid.getBlockData().setCell(rows[i], "fdShow", "2");
	}
	for(var i = 0 ; i < rows.length;i++){
		grid.getBlockData().setCell(rows[i], "fdKeyId", "");
	}
}

//单元格编辑后回调的方法 display - value
efgrid_onDataCellSaved = function( grid_id, row_index, col_index, cell_value ) 
{	
	var grid = efgrid.getGridObject("ef_grid_result"); 
	var rows = grid.getCheckedRows(); 
	var Ryear = $('#fdPlanYear').val();//获得年
	var Rmonth = $('#fdPlanMonth').val();//获得月
	var info=_getEi();
	var eiBlock=info.getBlock("cmes.cp.plantype");
	for(var i=0;i<eiBlock.getRows().length;i++)
	{
		var _value = eiBlock.getCell(i,"value");
		if(_value==cell_value)
		{			  
			var plantype = eiBlock.getCell(i,"display");
			var fdtitle = Ryear+"年"+Rmonth+"月"+plantype;
			grid.setCellValue(row_index, 1, fdtitle , TYPE_DATA);
			grid.refreshCell( row_index, 1, TYPE_DATA );
		}
	}
}

var hideAndShowSubButtons=function(status)
{
	if(!status)
	{
		efbutton.setButtonStatus("INSERT", false);
		efbutton.setButtonStatus("UPDATE", false);
		efbutton.setButtonStatus("DELETE", false);
		efbutton.setButtonStatus("UPLOAD", false);
		efbutton.setButtonStatus("REVERT", false);
	}
	else
	{
		efbutton.setButtonStatus("INSERT", true);
		efbutton.setButtonStatus("UPDATE", true);
		efbutton.setButtonStatus("DELETE", true);
		efbutton.setButtonStatus("UPLOAD", true);
		efbutton.setButtonStatus("REVERT", true);
	}
}

/**----------------------------从这里往下的方法都是附件操作相关方法------------------
 */
button_upload_onclick=function(){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return;
	var row_index=grid.getCheckedRowCount();
	var row=grid.getCheckedRows();
	if(row_index>1){
		EFAlert("只能选中一条项目信息后上传！");
		return;
	}
	var docId=grid.getCellValueByColumnName(row,"fdDocid");
	if(!isAvailable(docId)) {
		EFAlert("未指定文档号！", "系统警告");
		return false;
	}
	var url = "DispatchAction.do?efFormEname=EUAF3501";
		url = url + "&inqu_status-0-code=zm.cp";
	
	if(grid.getCellValueByColumnName(row,"fdPlanStatus")!="草拟")
	{
		url = url + "&editFlag=0";
	}else{
		url = url + "&editFlag=1";
	}
	url = url + "&inqu_status-0-docId="+docId+"&time=" + new Date().getTime();
	
	EFColorbox({href:url,title:"附件管理",width:"80%", height:"80%", iframe:true});
}
